package com.ag.utils;

import com.ag.exception.SysTipsException;

public class SysConstant {
	public static final int MAX_SELECT_COUNT = 5000;

	public static int STATUS_NORMAL = StatusEnum.ENABLE.v();// 正常
	public static int STATUS_DISABLE = StatusEnum.DISABLE.v();// 禁用
	public static int STATUS_DELETED = -10; //删除状态

	/**
	 * title: GlobalConstant.java 系统事件
	 *
	 * @author rplees
	 * @email rplees.i.ly@gmail.com
	 * @version 1.0
	 * @created 2015年11月6日 下午1:32:35
	 */
	public final static class SysCmd {
		public static final String PRE_INIT = "preInit";
		public static final String INIT = "init";
		public static final String FISRT_REQUSET = "fisrtRequset";
		public static final String APPLY_SITEMESH_CUSTOM_CONFIGURATION = "applySiteMeshCustomConfiguration";

		public static final String CMD_DIC_SYNC = "_cmd_dic_sync_";//字典同步
		public static final String CMD_ENUM_GROUP_SYNC = "_cmd_enum_group_sync_"; // 枚举分组同步
		public static final String NOTIFY_CACHE = "_notify_cache_";

		public static final String CMD_JOB_STOPFORCED = "_cmd_job_stopForced_";
		public static final String CMD_JOB_RESTART = "_cmd_job_reStart_";
	}
	
	/**
	 * 状态型枚举
	 * 
	 * @author rplees
	 * @email rplees.i.ly@gmail.com
	 * @version 1.0  
	 * @created May 9, 2020 5:46:26 PM
	 */
	public enum StatusEnum {
		ENABLE(1, "ENABLE", "正常"), AUDITING(0, "AUDITING", "审核中"), DISABLE(-1, "DISABLE", "禁用");

		Integer v;
		String label;
		String remark;

		StatusEnum(Integer v, String label, String remark) {
			this.remark = remark;
			this.label = label;
			this.v = v;
		}

		public Integer v() {
			return v;
		}

		public String label() {
			return label;
		}

		public String remark() {
			return remark;
		}
		
		public static String remark(Integer value) {
			StatusEnum of = of(value);
			return of == null ? "" : of.remark;
		}

		public static StatusEnum of(Integer value) {
			StatusEnum[] values = StatusEnum.values();
			for (StatusEnum e : values) {
				if(NumberUtils.equals(e.v, value)) {
					return e;
				}
			}
			throw new SysTipsException("找不到状态类型枚举");
		}
		
		public static StatusEnum ofNullableDisable(Integer value) {
			StatusEnum[] values = StatusEnum.values();
			for (StatusEnum e : values) {
				if(NumberUtils.equals(e.v, value)) {
					return e;
				}
			}
			
			return StatusEnum.ENABLE;
		}
	}
	
	public enum RetryEnum {
		SUCCESS(4, "成功"), WAIT_DO(0, "未处理"), DOING(1, "处理中"), WAIT_NEXT_RETRY(2, "等待下次重试"), FAIL(-1, "失败");

		Integer v;
		String remark;
		RetryEnum(Integer v, String remark) {
			this.remark = remark;
			this.v = v;
		}

		public Integer v() {
			return v;
		}
		
		public static String remark(Integer value) {
			RetryEnum of = of(value);
			return of == null ? "" : of.remark;
		}
		
		public static RetryEnum of(Integer value) {
			RetryEnum[] values = RetryEnum.values();
			for (RetryEnum e : values) {
				if(NumberUtils.equals(e.v, value)) {
					return e;
				}
			}
			return null;
		}
	}
	
	/**
	 * 
	 * @author rplees
	 * @email rplees.i.ly@gmail.com
	 * @version 1.0  
	 * @created May 9, 2020 5:46:26 PM
	 */
	public enum ProgressEnum {
		SUCCESS(4, "成功"), WAIT_DO(0, "未处理"), DOING(1, "处理中"), FAIL(-1, "失败"), CLOSE(-4, "关闭");

		Integer v;
		String remark;
		ProgressEnum(Integer v, String remark) {
			this.remark = remark;
			this.v = v;
		}

		public Integer v() {
			return v;
		}
		
		public String remark() {
			return remark;
		}
		
		public static String remark(Integer value) {
			ProgressEnum of = of(value);
			return of == null ? "" : of.remark;
		}
		
		public static ProgressEnum of(Integer value) {
			ProgressEnum[] values = ProgressEnum.values();
			for (ProgressEnum e : values) {
				if(NumberUtils.equals(e.v, value)) {
					return e;
				}
			}
			return null;
		}
	}
	
	public enum YesNoEnum {

		YES(1, true, "是"), NO(0, false, "否");

		Integer v;
		String remark;
		boolean bool;
		YesNoEnum(Integer v, boolean bool, String remark) {
			this.remark = remark;
			this.bool = bool;
			this.v = v;
		}

		public Integer v() {
			return v;
		}
		
		public boolean bool() {
			return bool;
		}
		
		public static boolean isOn(Integer v) {
			return isYes(v);
		}
		
		public static boolean isOff(Integer v) {
			return isNo(v);
		}
		
		public static boolean isYes(Integer v) {
			return ofNullableOff(v) == YES;
		}
		
		public static boolean isNo(Integer v) {
			return ofNullableOff(v) == NO;
		}
		
		public static YesNoEnum ofBool(Boolean b) {
			return (b == null) ? YesNoEnum.NO : b ? YesNoEnum.YES : YesNoEnum.NO;
		}
		
		public static YesNoEnum of(Boolean b) {
			return ofBool(b);
		}
		
		public static YesNoEnum of(Integer value) {
			YesNoEnum[] values = YesNoEnum.values();
			for (YesNoEnum e : values) {
				if(NumberUtils.equals(e.v, value)) {
					return e;
				}
			}
			throw new SysTipsException("找不到类型枚举");
		}
		
		public static YesNoEnum ofNullableOff(Integer value) {
			YesNoEnum[] values = YesNoEnum.values();
			for (YesNoEnum e : values) {
				if(NumberUtils.equals(e.v, value)) {
					return e;
				}
			}
			
			return YesNoEnum.NO;
		}
	
	}
	/**
	 * 开关型枚举
	 * 
	 * @author rplees
	 * @email rplees.i.ly@gmail.com
	 * @version 1.0  
	 * @created May 9, 2020 5:46:26 PM
	 */
	public enum BooleanEnum {
		ON(1, true, "开启"), OFF(0, false, "关闭");

		Integer v;
		String remark;
		boolean bool;
		BooleanEnum(Integer v, boolean bool, String remark) {
			this.remark = remark;
			this.bool = bool;
			this.v = v;
		}

		public Integer v() {
			return v;
		}
		
		public boolean bool() {
			return bool;
		}
		
		public static boolean isOn(Integer v) {
			return ofNullableOff(v) == ON;
		}
		
		public static boolean isOff(Integer v) {
			return ofNullableOff(v) == OFF;
		}
		
		public static BooleanEnum ofBool(Boolean b) {
			return (b == null) ? BooleanEnum.OFF : b ? BooleanEnum.ON : BooleanEnum.OFF;
		}
		
		public static BooleanEnum of(Boolean b) {
			return ofBool(b);
		}
		
		public static BooleanEnum of(Integer value) {
			BooleanEnum[] values = BooleanEnum.values();
			for (BooleanEnum e : values) {
				if(NumberUtils.equals(e.v, value)) {
					return e;
				}
			}
			throw new SysTipsException("找不到开关类型枚举");
		}
		
		public static BooleanEnum ofNullableOff(Integer value) {
			BooleanEnum[] values = BooleanEnum.values();
			for (BooleanEnum e : values) {
				if(NumberUtils.equals(e.v, value)) {
					return e;
				}
			}
			
			return BooleanEnum.OFF;
		}
	}
}
